package oop.inherit.account;

public class Account {

    //属性
    //账号
    private int id;
    //余额
    private double balance;
    //年利率
    private double annualInterestRate;

    //方法
    public Account (int id, double balance, double annualInterestRate ){
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }

    /**
     * 年利率 * 余额 / 12 / 余额
     * @return
     */
    public double getMonthlyInterest(){
        return this.annualInterestRate/12;
    }

    /**
     * 取款
     * @param amount
     */
    public void withdraw (double amount){

        double b = this.balance;
        b -= amount;
        if(b<0){
            System.out.println("余额不足");
        }else{
            this.balance = b;
        }
    }

    public void deposit (double amount){
        this.balance += amount;
    }
}
